# pandas 读取excel数据方便
import pandas as pd
# xlwings 写入比较好用
import xlwings as xw

file_path = r'C:\Users\cdou\Desktop\gzb.xlsx'
data_frame = pd.read_excel(file_path, header=0)
# print(data_frame['ModuNO'])
df2l = list(data_frame['ModuNO'])
print(df2l)
dl = []
for i in df2l:
    if i.find('9',-1) == 10:
        dl.append(i)

print(dl)

# 写入数据部分
try:
    app = xw.App(visible=False, add_book=False)
    app.display_alerts = False
    app.screen_updating = False
    wb = app.books.open(file_path)  # 这将创建一个新的工作簿
    sht = wb.sheets[0]
    sht.range("B1").value='结果'
    sht.range('B2').options(transpose=True).value = dl
    sht.range("C1").value='结果'
    sht.range('C2').options(transpose=True).value = dl
    wb.save()
    wb.close()
    app.quit()
    print('操作成功！！')
except:
    wb.close()
    app.quit()

